package department.fc.controller;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import department.fc.common.AttributeAndView;
import department.fc.common.Controller;
import department.fc.domain.Department;
import department.fc.service.DepartmentService;

public class DepartmentListController implements Controller{

	@Override
	public AttributeAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
//		1. 요청을 받는다.
//		2. Business Logic - Model 호출 
		DepartmentService service = DepartmentService.getInstance();
		AttributeAndView av = null;
		
		try{
			//정상적으로 처리 되었을 경
			ArrayList<Department> list = service.getDepartmentList();
			
			av = new AttributeAndView(false, "/WEB-INF/jsp/dept/department_list.jsp", "departmentList", list);
			
			
		}catch(SQLException e){
			e.printStackTrace();
			av = new AttributeAndView(false, "WEB-INF/jsp/error.jsp", "error_message", e.getMessage());
		}
		return av;
	}

}